Skip to main content

Testing

Testing


Pest datasets (scoped per folder)

Use folder-scoped datasets to keep data close to tests and avoid manual loads in Pest.php (Pest Datasets).

  • Create tests/Unit/Datasets.php (or tests/Feature/.../Datasets.php) and define datasets with dataset('name', ...).
  • Pest automatically loads Datasets.php within that folder and scopes it to tests in the folder.

Minimal example:

// tests/Unit/Datasets.php
dataset('htmlSanitizerDocumentCase', fn () => [[[
'input' => '<!DOCTYPE html><html>...</html>',
'anchorCount' => 6,
]]]);

In the test:

it('sanitizes html', function (array $case) {
$clean = HtmlSanitizer::sanitize($case['input']);
expect($clean)->not()->toContain('<html>');
})->with('htmlSanitizerDocumentCase');

Notes:

  • If your test signature is function (array $case), each dataset row must be a single argument: use [[[ ... ]]].
  • Avoid glob() or require in tests/Pest.php. Prefer Datasets.php per folder or tests/Datasets/*.php for truly global datasets.
X

Graph View